package org.example;

import java.util.Scanner;

/*class Solution{
    public int countSegment(String s){
        int count = 1;
        for (int i = 0; i < s.length(); i++) {//遍历整个字符串
            if(s.charAt(i) == ' '){//如果碰到了空格，说明单词数量+1
                count++;
            }
        }
        return count;
    }
}*/

public class Test {
    public static void main(String[] args) {
        Integer a1 = 100;
        Integer a2 = 100;
        System.out.println(a1 == a2);//true

        Integer a3 = 200;
        Integer a4 = 200;
        System.out.println(a3 == a4);//false

        Integer a5 = 200;
        Integer a6 = 200;
        System.out.println(a5.equals(a6));
    }
    public static void main3(String[] args) {
        //字符串最后一个单词的长度
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            String s = in.nextLine();
            int k = s.lastIndexOf(' ');
            String ret = s.substring(k + 1);
            System.out.println(ret.length());
        }
    }
    public static void main2(String[] args) {
        String str = "name=zhangsan&age=14";
        String []strings = str.split("&");//通过split进行分离
        for (int i = 0; i < strings.length; i++) {
            System.out.println(strings[i]);
        }
        System.out.println("==============");
        String str1 = "hello world and computer";
        String []strings1 = str1.split(" ", 2);
        for (int i = 0; i < strings1.length; i++) {
            System.out.println(strings1[i]);
        }
        System.out.println("=================");
        String str2 = "192.164.0.0.2";
        String []strings2 = str2.split("\\.", 3);
        for (int i = 0; i < strings2.length; i++) {
            System.out.println(strings2[i]);
        }
        System.out.println("================");
        String str3 = "      addd aa  sss ";
        String str4 = str3.trim();//只能求除左右两边的空格
        System.out.println(str4);
    }
    public static void main1(String[] args) {
        //定义一个字符串地两种方法
        /*String str = "good";
        System.out.println(str);
        System.out.println(str.length());
        System.out.println("good".length());
        String str2 = new String("123");
        System.out.println(str2);
        System.out.println(str2.length());
        System.out.println("123".length());*/

        /*String str1 = new String("hello");
        String str2 = new String("hello");
        System.out.println(str1 == str2);//输出为false,因为str1,str2指向的是两个不同的对象
        System.out.println(str1.equals(str2));//输出为true,因为str1和str2指向的是两个相同的对象*/
        //字符串的比较
        String str1 = new String("hello");
        String str2 = new String("WORLD");
        System.out.println(str1.compareTo(str2));
        String str3 = str1.toUpperCase();//将小写转换为大写
        System.out.println(str3);
        String str4 = str2.toLowerCase();//将大写转化为小写
        System.out.println(str4);
        String ret = str1.replace("he", "bi");
        System.out.println(ret);
        //如果大于输出为正数，小于就是负数，0就是相等
        /**
         * 比较逻辑
         * 如果两个字符串的长度相等，比较第一个不同的位置并返回ASCII码的差值
         * 如果两个字符串的长度不同，先比较两个字符串的差值个，在这个差值范围内就能比较出两个字符串的大小
         * 但如果都一样就比较谁长谁大
         */
    }
}
